<template>
	<div class="moneymanage">
		<el-radio-group class="headradioBtn_type" v-model="headradioBtn_type.radio"   @change="headradioBtnchange_type">
			<el-radio-button label="全部收费" class="first"></el-radio-button>
			<el-radio-button label="报名收费"></el-radio-button>
			<el-radio-button label="商品收费"></el-radio-button>
			<el-radio-button label="订金收费" class="last"></el-radio-button>
		</el-radio-group>
		<div class="content-moneymanage">
			<div class="t-title">{{topTitle}}</div>
			<el-radio-group class="headradioBtn_money" v-model="headradioBtn_money.radio"   @change="headradioBtnchange_money">
				<el-radio-button label="总收款">
					<img class="btnIco" src="../../assets/img/processing_center/moneytotal.png">
					<div class="ccbox">
						<span class="number"><span class="ico">￥</span>{{formateDisplayMoney(headradioBtn_money.data.sum)}}</span>
						<span class="txt">总收款</span>
					</div>
				</el-radio-button>
				<el-radio-button label="现金收款">
					<img class="btnIco" src="../../assets/img/processing_center/cash.png">
					<div class="ccbox">
						<span class="number"><span class="ico">￥</span>{{formateDisplayMoney(headradioBtn_money.data.cash)}}</span>
						<span class="txt">现金收款</span>
					</div>
				</el-radio-button>
				<el-radio-button label="微信收款">
					<img class="btnIco" src="../../assets/img/processing_center/wechat.png">
					<div class="ccbox">
						<span class="number"><span class="ico">￥</span>{{formateDisplayMoney(headradioBtn_money.data.wechat)}}</span>
						<span class="txt">微信收款</span>
					</div>
				</el-radio-button>
				<el-radio-button label="支付宝收款">
					<img class="btnIco" src="../../assets/img/processing_center/alipay.png">
					<div class="ccbox">
						<span class="number"><span class="ico">￥</span>{{formateDisplayMoney(headradioBtn_money.data.alipay)}}</span>
						<span class="txt">支付宝收款</span>
					</div>
				</el-radio-button>
				<el-radio-button label="银联收款">
					<img class="btnIco" src="../../assets/img/processing_center/unionpay.png">
					<div class="ccbox">
						<span class="number"><span class="ico">￥</span>{{formateDisplayMoney(headradioBtn_money.data.unionpay)}}</span>
						<span class="txt">银联收款</span>
					</div>
				</el-radio-button>
			</el-radio-group>
			<div class="tableBox">
				<div class="headcontrolsbox">
					<div class="left">
						<template>
							<el-select class="payeeselect comSearchInput" v-model="headControls.payee.select" clearable
								collapse-tags  placeholder="收款人" @change="payeeSelectChange">
								<el-option
								v-for="item in headControls.payee.data"
								:key="item.value"
								:label="item.label"
								:value="item.value">
								</el-option>
							</el-select>
						</template>
						<el-input class="paraminput comSearchInput" ref="inputKeyWords"
							placeholder="搜索 学员姓名、联系电话"
							suffix-icon="el-icon-search"
							v-model="headControls.param"
							clearable
							@clear="inputKeyWordsClear"
							@keyup.enter.native="queryBtnClick">
						</el-input>
						<!-- <el-button class="query" @click="queryBtnClick">查询</el-button> -->
						<div class="search_btn" @click="queryBtnClick">搜索</div>
					</div>
					<div class="right">
						<el-date-picker
							v-model="headControls.timeselect.selfTime" @change="updateSelfTime"
							type="datetimerange"
							ref="selfTime"
							range-separator="至"
							start-placeholder="开始日期" 
							end-placeholder="结束日期">
						</el-date-picker>
						<el-radio-group class="timeselect" v-model="headControls.timeselect.radio"   @change="timeselectchange">
							<el-radio-button label="今日"></el-radio-button>
							<el-radio-button label="本周"></el-radio-button>
							<el-radio-button label="本月"></el-radio-button>
							<el-radio-button label="自定义" ref="selfBtn"></el-radio-button>
						</el-radio-group>
					</div>
				</div>
				<template>
					<el-table
						ref="tableAll"
						:data="moneyTableData"
						stripe
						style="'width: 100%;font-size:0.16rem;"
						class="moneyTable"
						>
						<el-table-column
						prop="orderSigupId"
						width="220"
						label="订单号">
						</el-table-column>
						<el-table-column
						prop="createTime"
						label="收款时间">
						</el-table-column>
						<el-table-column
						prop="realMoney"
						label="收款金额">
							<template slot-scope="scope">
								<span>￥{{scope.row.realMoney}}</span>
							</template>
						</el-table-column>
						<el-table-column
						prop="billModeName"
						label="收入类型">
						</el-table-column>
						<el-table-column
						prop="createUserName"
						label="收款人">
						</el-table-column>
						<el-table-column
						prop="moneyStatu"
						label="状态">
							<template slot-scope="scope">
								<span v-if="scope.row.checkshow">待审核</span>
								<span v-else-if="scope.row.payshow">待支付</span>
								<span v-else>已入账</span>
							</template>
						</el-table-column>
						<el-table-column
						prop="query"
						label="操作">
						<template slot-scope="scope">
							<el-button style="font-size:0.16rem;"  @click="moneyTableRowClick(scope.row)" type="text" size="medium">查看</el-button>
							<el-button style="font-size:0.16rem;"  v-if="scope.row.checkshow"
							 @click="checkTableRow(scope.row)" type="text" size="medium">审核</el-button>
							<el-button style="font-size:0.16rem;"  v-if="scope.row.payshow"
							 @click="payTableRow(scope.row)" type="text" size="medium">支付</el-button>
						</template>
						</el-table-column>

					</el-table>
					<el-table
						ref="tableEnroll"
						:data="moneyTableData"
						stripe
						style="'width: 100%;font-size:0.16rem;"
						class="moneyTable"
						>
						<el-table-column
						prop="orderSigupId"
						width="220"
						label="订单号">
						</el-table-column>
						<el-table-column
						prop="studentName"
						label="学员姓名">
						</el-table-column>
						<el-table-column
						prop="studentNo"
						label="学号">
						</el-table-column>
						<el-table-column
						prop="orderNo"
						label="合同号">
						</el-table-column>
						<el-table-column
						prop="enroll"
						label="报名">
							<template slot-scope="scope">
								{{scope.row.courseName||""}}<br>
								{{scope.row.className||""}}
							</template>
						</el-table-column>
						<el-table-column
						prop="createUserName"
						label="收款人">
						</el-table-column>
						<el-table-column
						width="160"
						prop="createTime"
						label="收款时间">
						</el-table-column>
						<el-table-column
						prop="realMoney"
						label="实际收款">
							<template slot-scope="scope">
								<span>￥{{scope.row.realMoney}}</span>
							</template>
						</el-table-column>
						<el-table-column
						prop="executeUserName"
						label="跟单人">
						</el-table-column>
						<el-table-column
						prop="moneyStatu"
						label="状态">
							<template slot-scope="scope">
								<span v-if="scope.row.checkshow">待审核</span>
								<span v-else-if="scope.row.payshow">待支付</span>
								<span v-else>已入账</span>
							</template>
						</el-table-column>
						<el-table-column
						prop="query"
						label="操作">
						<template slot-scope="scope">
							<el-button style="font-size:0.16rem;" @click="moneyTableRowClick(scope.row)" type="text" size="medium">查看</el-button>
							<el-button style="font-size:0.16rem;" v-if="scope.row.checkshow"
							 @click="checkTableRow(scope.row)" type="text" size="medium">审核</el-button>
							<el-button style="font-size:0.16rem;" v-if="scope.row.payshow"
							 @click="payTableRow(scope.row)" type="text" size="medium">支付</el-button>
						</template>
						</el-table-column>

					</el-table>
					<el-table
						ref="tableBuy"
						:data="moneyTableData"
						stripe
						style="'width: 100%;font-size:0.16rem;"
						class="moneyTable"
						>
						<el-table-column
						prop="studentName"
						label="学员姓名">
						</el-table-column>
						<el-table-column
						prop="studentPhone"
						label="联系电话">
						</el-table-column>
						<el-table-column
						prop="receiptNo"
						label="收据">
						</el-table-column>
						<el-table-column
						prop="signupGoodsData_goodsName"
						label="购买商品">
						</el-table-column>
						<!-- <el-table-column
						prop="realMoney"
						label="商品单价">
						</el-table-column> -->
						<el-table-column
						prop="signupGoodsData_goodsNum"
						label="购买数量">
						</el-table-column>
						<el-table-column
						prop="realMoney"
						label="支付金额">
							<template slot-scope="scope">
								<span>￥{{scope.row.realMoney}}</span>
							</template>
						</el-table-column>
						<el-table-column
						prop="createTime"
						label="购买时间">
						</el-table-column>
						<el-table-column
						prop="createUserName"
						label="收款人">
						</el-table-column>
						<el-table-column
						prop="query"
						label="操作">
						<template slot-scope="scope">
							<el-button style="font-size:0.16rem;" @click="moneyTableRowClick(scope.row)" type="text" size="medium">查看</el-button>
							<!-- <el-button  v-if="scope.row.checkshow"
							 @click="checkTableRow(scope.row)" type="text" size="medium">审核</el-button>
							<el-button  v-if="scope.row.payshow"
							 @click="payTableRow(scope.row)" type="text" size="medium">支付</el-button> -->
						</template>
						</el-table-column>

					</el-table>
					<el-table
						ref="tableDeposit"
						:data="moneyTableData"
						stripe
						style="'width: 100%;font-size:0.16rem;"
						class="moneyTable"
						>
						<el-table-column
						prop="studentName"
						label="学员姓名">
						</el-table-column>
						<el-table-column
						prop="studentPhone"
						label="联系电话">
						</el-table-column>
						<el-table-column
						prop="createTime"
						label="支付时间">
						</el-table-column>
						<el-table-column
						prop="realMoney"
						label="订金金额">
							<template slot-scope="scope">
								<span>￥{{scope.row.realMoney}}</span>
							</template>
						</el-table-column>
						<el-table-column
						prop="createUserName"
						label="收款人">
						</el-table-column>

						<el-table-column
						prop="query"
						label="操作">
						<template slot-scope="scope">
							<el-button style="font-size:0.16rem;" @click="moneyTableRowClick(scope.row)" type="text" size="medium">查看</el-button>
							<!-- <el-button  v-if="scope.row.orderSignupEntity.orderSignupState==1&&scope.row.payMode<=2"
							 @click="checkTableRow(scope.row)" type="text" size="medium">审核</el-button>
							 <el-button  v-if="scope.row.orderSignupEntity.orderPayState==1&&scope.row.payMode>2"
							 @click="payTableRow(scope.row)" type="text" size="medium">支付</el-button> -->
						</template>
						</el-table-column>

					</el-table>
				</template>
				<el-pagination
					:page-sizes="[10, 20, 30, 40,50,100]"
					:page-size="searchListParam.pageSize"
					layout="total, sizes, prev, pager, next, jumper"
					:total="pagination.total"
					:current-page="searchListParam.currPage"
					@current-change="handleCurrentChange"
					@size-change="handleSizeChange">
				</el-pagination>
			</div>
			<el-dialog
				class="checkpopup"
				:modal="false"
				:close-on-click-modal="false"
				title="确定该笔订单已入账吗？"
				:visible.sync="checkPopup.visible">
				<el-row>
					<span>订单号：</span>
					<span>{{checkPopup.orderNo}}</span>
				</el-row>
				<el-row>
					<span>收款金额：</span>
					<span>￥{{checkPopup.money}}</span>
				</el-row>
				<el-row>
					<span>收款人：</span>
					<span>{{checkPopup.payee}}</span>
				</el-row>
				<span slot="footer" class="dialog-footer">
					<el-button @click="checkPopup.visible = false">取 消</el-button>
					<el-button @click="checkOrders">确 定</el-button>
				</span>
			</el-dialog>
			<el-dialog class="chargespopup" :title="moneyDetailsPopup.title" :visible.sync="moneyDetailsPopup.visible"
				:center="moneyDetailsPopup.operationType==2">
				<chargespopup ref="chargespopup" :chargespopup='moneyDetailsPopup.data'
				 @hideMe="hideChargesPopup" @success="updateMoneyList"></chargespopup>
			</el-dialog>
			<enrollPay v-show="enrollPayPopup.visible" ref="enrollPay" @ok="enrollPaypayOk" @back="enrollPaybackConfirm"></enrollPay>
			<!-- 支付成功反馈弹窗 -->
			<el-dialog class="paySuccess"
			:modal="false"
			:visible.sync="paySuccess.paySuccessVisible"
			>
				<enrollsuccess ref="enrollsuccess" @ok="successOk"></enrollsuccess>
			</el-dialog>
			
		</div>
		
	</div>
</template>

<script>
import chargespopup from './common/chargespopup'
import enrollPay from "@/components/clue_manage/subpage/clue_enroll_pay";
import enrollsuccess from "./common/pay_success";
// import { setTimeout } from 'timers';
	export default{
		components:{chargespopup,enrollPay,enrollsuccess},
		// props:[''],
		data(){
			return {
				topTitle:'全部收费',
				/**收费列表：全局搜索条件 */
				searchListParam:{
					campusId:this.$store.state.campusId,
					pageSize:10,
					queryType:1,
					billMode:'',
					accountUserId:'',
					currPage:1,
					payMode:'',
					keyName:'',
					startTime:'',
					endTime:''
				},
				headradioBtn_type:{
					radio:'全部收费'
				},
				headradioBtn_money:{
					radio:'总收款',
					data:{
						sum:0,
						cash:0,
						wechat:0,
						alipay:0,
						unionpay:0
					}
				},
				headControls:{
					payee:{
						createUserNameList:[],
						data:[],
						select:''
					},
					param:'',
					timeselect:{
						radio:'今日',
						pre_radio:'今日',
						selfTime:[new Date(), new Date()]
					}
				},
				moneyTableData: [],
				/**分页 */
				pagination:{
					total:0
				},
				//费用详情、退费详情弹窗
				moneyDetailsPopup:{
					visible:false,
					title:'费用详情',
					data:null,
					operationType:0
				},
				checkPopup:{
					visible:false,
					orderNo:'CN001',
					money:1200,
					payee:'张无忌'
				},
				enrollPayPopup:{
					visible:false,

				},
				paySuccess:{
					paySuccessVisible:false,

				}
			};
		},
		methods:{
			init(){
				let dict=JSON.parse(tool.getItem(window.lsKey.dict));
				this._billmode=dict.bill_mode;
				this._courseMode=dict.course_mode;
				this.course_time_mode=dict.course_time_mode;
				// console.log(dict)

				this.resetSearchParam();//重置搜索条件

				this.updateUserList();
				this.updateTypeMoney();//各渠道支付统计
				this.updateMoneyList();//收费列表
				this.changeVisibleTable();
			},
			campusChange : function(campusId) { //校区改变
				this.searchListParam.campusId = campusId;
				this.init();
			},
			/**更新收款人列表 */
			updateUserList(){
				let self=this;
				api.userListByCampus({campusId:this.searchListParam.campusId}).then(function(d){
					// console.log(d)
					if(d.result=='处理成功'){
						self.headControls.payee.data=[];
						for(let i=0;i<d.userList.length;i++){
							let row=d.userList[i];
							self.headControls.payee.data.push({
								value: row.userId,
								label: row.nickName
							});
						}
					}
				});
			},
			/**更新各支付渠道收费总计情况 */
			updateTypeMoney(){
				let self=this;
				let startTime=this.searchListParam.startTime;
				let endTime=this.searchListParam.endTime;
				let billMode=this.searchListParam.billMode;
				self.headradioBtn_money.data={
					sum:0,
					cash:0,
					wechat:0,
					alipay:0,
					unionpay:0
				}
				// console.log(billMode)
				api.chargeByPaymode({startTime:startTime,endTime:endTime,billMode:billMode,campusId:this.searchListParam.campusId})
				.then(function(d){
					// console.log(d);
					if(d.result=='操作成功'){
						let list=d.info;
						for(let i=0;i<list.length;i++){
							let row=list[i];
							switch(row.payMode){
								case 2:{
									self.headradioBtn_money.data.cash=row.realMoney;
									break;
								}
								case 3:{
									self.headradioBtn_money.data.wechat=row.realMoney;
									break;
								}
								case 4:{
									self.headradioBtn_money.data.alipay=row.realMoney;
									break;
								}
								case 1:{
									self.headradioBtn_money.data.unionpay=row.realMoney;
									break;
								}
								// default:{
								// 	self.headradioBtn_money.data.sum=row.realMoney;
								// 	break;
								// }
							}
						}
						self.headradioBtn_money.data.sum=self.headradioBtn_money.data.cash+
						self.headradioBtn_money.data.wechat+
						self.headradioBtn_money.data.alipay+
						self.headradioBtn_money.data.unionpay;
					}
				});
			},
			/**格式化显示数字 */
			formateDisplayMoney(num){
				let result=0;
				let numstr=num.toString();
				if(numstr.length>9){
					if(num>9999){
						result=(num/10000).toFixed(2)+'万';
						if(result.length>9){
							result=(num/100000000).toFixed(3)+'亿';
						}
					}
					else{
						result=num.toFixed(2);
					}
				}
				else if(numstr.length<=9)
					result=numstr;
				return result;
			},
			/**重置搜索条件（包括输入框的文本） */
			resetSearchParam(){
				//重置翻页
				this.searchListParam.pageSize=10;
				this.searchListParam.currPage=1;
				//重置时间
				let today=tool.getTimeObjByType(1);
				this.searchListParam.startTime=today.startTime;
				this.searchListParam.endTime=today.endTime;
				this.headControls.timeselect.radio='今日';
				//重置输入框
				this.searchListParam.keyName='';
				this.headControls.param='';
				this.searchListParam.accountUserId='';
				this.headControls.payee.select='';
				this.searchListParam.payMode='';
				this.headradioBtn_money.radio='总收款';
				// this.searchListParam.billMode='';
				// this.headradioBtn_type.radio='全部收费';
				// this.topTitle='全部收费';

			},
			/**更新收费列表数据
			 * pageSize 每页几条记录
			 * currPage 当前页号，1开始
			 * payMode 支付类型
			 * keyName 搜索关键字
			 * startTime 开始时间(可选)
			 * endTime 结束时间(可选)
			 */
			updateMoneyList(currPage){
				let self=this;
				this.searchListParam.currPage=1;
				if(currPage){
					this.searchListParam.currPage=currPage;
				}
				api.moneyList(this.searchListParam)
				.then(function(d){
					// console.log(d)
					if(d.result=='操作成功'){
						//初始化翻页
						self.pagination.total=d.totalCount;
						for(let i=0;i<d.list.length;i++){
							d.list[i].billModeName=self.matchBillMode(d.list[i].billMode);
							// if(!self.headControls.payee.createUserNameList.includes(d.list[i].createUserName)){
							// 	self.headControls.payee.createUserNameList.push(d.list[i].createUserName)
							// }
							if(d.list[i].orderSignupEntity){
								if(d.list[i].orderSignupEntity.orderSignupState==1&&d.list[i].payMode<=2){
									d.list[i].checkshow=true;
								}
								if(d.list[i].orderSignupEntity.orderPayState==1&&d.list[i].payMode>2){
									d.list[i].payshow=true;
								}
							}
							
							//商品收费处理
							if(self.searchListParam.billMode==6&&d.list[i].signupGoodsData&&d.list[i].signupGoodsData.length>0){
								// debugger
								let goodsName=d.list[i].signupGoodsData[0].goodsName,goodsNum=0,goodsTotalMoney=0;
								if(d.list[i].signupGoodsData.length>1)goodsName+='...';
								d.list[i].signupGoodsData.forEach(ele=>{
									goodsNum+=ele.goodsNum;
									goodsTotalMoney+=ele.realMoney;
								});
								d.list[i].signupGoodsData_goodsName=goodsName;
								d.list[i].signupGoodsData_goodsNum=goodsNum;
								d.list[i].signupGoodsData_goodsTotalMoney=goodsTotalMoney;
							}
						}
						
						self.moneyTableData=d.list;
					}
				});
			},
			/**匹配得到billlmode的中文含义 */
			matchBillMode(value){
				for(let i=0;i<this._billmode.length;i++){
					if(this._billmode[i].value===value){
						return this._billmode[i].name;
					}
				}
			},
			matchCourseTimeMode(value){
				let course_time_mode=this.course_time_mode;
				for(let j =0;j<course_time_mode.length;j++){
					if(value==course_time_mode[j].value){
						return course_time_mode[j].name;
					}
				}
			},
			changeVisibleTable(){
				switch(this.topTitle){
					case '全部收费':{
						this.$refs.tableAll.$el.style.display='block';
						this.$refs.tableEnroll.$el.style.display='none';
						this.$refs.tableBuy.$el.style.display='none';
						this.$refs.tableDeposit.$el.style.display='none';
						break;
					}
					case '报名收费':{
						this.$refs.tableAll.$el.style.display='none';
						this.$refs.tableEnroll.$el.style.display='block';
						this.$refs.tableBuy.$el.style.display='none';
						this.$refs.tableDeposit.$el.style.display='none';
						break;
					}
					case '商品收费':{
						this.$refs.tableAll.$el.style.display='none';
						this.$refs.tableEnroll.$el.style.display='none';
						this.$refs.tableBuy.$el.style.display='block';
						this.$refs.tableDeposit.$el.style.display='none';
						break;
					}
					case '订金收费':{
						this.$refs.tableAll.$el.style.display='none';
						this.$refs.tableEnroll.$el.style.display='none';
						this.$refs.tableBuy.$el.style.display='none';
						this.$refs.tableDeposit.$el.style.display='block';
						break;
					}
				}
			},
			/**收费类型选择 */
			headradioBtnchange_type(d){
				this.topTitle=d;
				let match={
					'全部收费':'',
					'报名收费':1,
					'商品收费':6,
					'订金收费':3
				};
				let billmode=match[d];
				
				this.resetSearchParam();//重置搜索条件

				this.searchListParam.billMode=billmode;
				this.updateTypeMoney();//各渠道支付统计
				this.updateMoneyList();
				this.changeVisibleTable();
			},
			/**收款方式选择 */
			headradioBtnchange_money(d){
				// console.log(d);
				let match={
					'总收款':'',
					'现金收款':2,
					'微信收款':3,
					'支付宝收款':4,
					'银联收款':1
				};
				let paymode=match[d];
				this.searchListParam.payMode=paymode;
				this.updateMoneyList();
			},
			/**收款人-下拉选择 */
			payeeSelectChange(d){
				// console.log(d);
				this.searchListParam.accountUserId=d||'';
				// this.updateMoneyList();
			},
			/**搜索条件清空 */
			inputKeyWordsClear(){
				this.searchListParam.keyName='';
				// this.updateMoneyList();
			},
			/**查询按钮点击 */
			queryBtnClick(){
				let keywords=this.headControls.param;
				this.searchListParam.keyName=keywords;
				this.updateMoneyList();
			},
			/**时间切换 */
			timeselectchange(d){
				//自定义时间选取
				if(d==='自定义'){
					this.$refs.selfTime.focus();
					this.headControls.timeselect.radio=this.headControls.timeselect.pre_radio;
					return;
				}
				let timeobj;
				if(d=='今日'){
					timeobj=tool.getTimeObjByType(1);
				}
				else if(d=='本周'){
					timeobj=tool.getTimeObjByType(2);
				}
				else if(d=='本月'){
					timeobj=tool.getTimeObjByType(3);
				}
				this.headControls.timeselect.pre_radio=d;
				this.searchListParam.startTime=timeobj.startTime;
				this.searchListParam.endTime=timeobj.endTime;
				this.updateTypeMoney();//各渠道支付统计
				this.updateMoneyList();//收费列表
			},
			/**自定义时间 */
			updateSelfTime(d){
				if(!d)return;
				this.headControls.timeselect.radio='自定义';
				let start=formateDate(d[0]),end=formateDate(d[1]);
				this.searchListParam.startTime=start;
				this.searchListParam.endTime=end;
				this.updateTypeMoney();//各渠道支付统计
				this.updateMoneyList();//收费列表
				function formateDate(t=new Date()){
					let year=t.getFullYear();
					let month=t.getMonth()+1;
					month=month<10?'0'+month:month;
					let day=t.getDate();
					day=day<10?'0'+day:day;
					let hour=t.getHours();
					hour=hour<10?'0'+hour:hour;
					let minute=t.getMinutes();
					minute=minute<10?'0'+minute:minute;
					let second=t.getSeconds();
					second=second<10?'0'+second:second;
					return year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second;
				}
			},
			/**表格 行查看点击 */
			moneyTableRowClick(d){
				// console.log(d)
				this.moneyDetailsPopup.visible=true;
				let type=this.headradioBtn_type.radio;
				if(type=='全部收费'){
					if(d.billModeName=='报名'){
						type='报名收费';
					}
					else if(d.billModeName=='买商品'){
						type='商品收费';
					}
					else if(d.billModeName=='收订金'){
						type='订金收费';
					}
				}
				this.showChargesPopup(type,d,1);
				
			},
			/**审核 */
			checkTableRow(d){
				//简略小弹窗
				// this.checkPopup.visible=true;
				// this.checkPopup.orderNo=d.orderSignupEntity.orderSigupId;
				// this.checkPopup.money=d.realMoney;
				// this.checkPopup.payee=d.createUserName;
				// this.checkPopup.orderSigupId=d.orderSignupEntity.orderSigupId;

				//在收退费详情页审核
				this.moneyDetailsPopup.visible=true;
				let type=this.headradioBtn_type.radio;
				if(type=='全部收费'){
					if(d.billModeName=='报名'){
						type='报名收费';
					}
					else if(d.billModeName=='买商品'){
						type='商品收费';
					}
					else if(d.billModeName=='收订金'){
						type='订金收费';
					}
				}
				this.showChargesPopup(type,d,2);
			},
			checkOrders(){
				let self=this;
				api.setAuditOrder({orderSigupId:this.checkPopup.orderSigupId}).then(function(d){
					// console.log(d);
					if(d.result=='操作成功'){
						self.$message({
							message: '操作成功！',
							type: 'success'
						});
						self.checkPopup.visible=false;
						self.updateMoneyList();
					}
					
				});
			},
			/**支付 */
			payTableRow(d){
				// console.log(d);
				this.enrollPayPopup.visible=true;
				let countList=[];
				let courselist=d.signupCourseData||[];
				let realMoney=0;
				// if(courselist.length>0)courselist[0].name='请支付';
				courselist.forEach(d=>{
					d.type=d.classId?'班级':'课程';
					d.name='';
					realMoney=realMoney+d.realMoney;
				});
				let goodslist=d.signupGoodsData||[];
				goodslist.forEach(d=>{
					d.type='商品';
					realMoney=realMoney+d.realMoney;
				});
				countList=goodslist.concat(courselist);
				this.$refs.enrollPay.init({},countList, 
					{
						payName:d.payMode==3?'wxpay':'alipay',
						// payTitle:'支付',
						realMoney:realMoney,
						orderSigupId:d.orderSignupEntity.orderSigupId,
						realName:d.studentName,
						parentData:[{parentName:d.parentName,phone:d.studentPhone}],
						money:d.realMoney+Number(d.discount),//应收总计
						realMoney:d.realMoney,//实际收款
						signUpUseEarnestMoney:d.signUpUseEarnestMoney//定金抵扣
					}
				);
			},
			enrollPaypayOk(countList,info){
				// console.log(countList);
				// console.log(info)
				this.enrollPayPopup.visible=false;
				this.paySuccess.paySuccessVisible=true;
				//处理字段
				let orderlist=[];
				for(let i=0;i<countList.length;i++){
					let row=countList[i];
					if(row.courseId){
						let classmode=row.courseMode;
						this._courseMode.forEach((row)=>{
							if(row.value===classmode){
								classmode=row.name;
							}
						});
						let price=(row.courseMoney/row.courseHour).toFixed(2);
						price=isNaN(price)?row.courseMoney:price;
						let unit='课时';
						if(!row.coursePackage){
							unit='';
						}
						else if(row.coursePackage.chargeMode==3){
							unit=this.matchCourseTimeMode(row.coursePackage.courseTimeMode);
						}
						orderlist.push({
							mode:classmode,
							name:(row.courseName?(row.courseName+'\n'):'')+(row.className||''),
							totalPrice:row.courseMoney,
							unitPrice:price,
							unit:unit,
							count:row.courseHour,
							totalMoney:row.courseMoney,
							discount:row.discountMoney,
							receivable:row.realMoney
						});
					}
					else{
						orderlist.push({
							mode:'商品',
							name:row.goodsName,
							totalPrice:(row.goodsOneMoney*row.goodsNum),
							unitPrice:row.goodsOneMoney,
							unit:'个',
							count:row.goodsNum,
							totalMoney:row.totalMoney,
							discount:'0',
							receivable:row.realMoney
						});
					}
					
				}
				
				this.$nextTick(()=>{
					this.$refs.enrollsuccess.init({
						name:'支付',
						realName:info.realName,
						parentData:info.parentData,
						type:'办理中心'
					}, orderlist, info);
					this.updateMoneyList();
				});
				
			},
			enrollPaybackConfirm(d){
				
			},
			successOk(){
				this.paySuccess.paySuccessVisible=false;
			},
			/**表格翻页 */
			handleCurrentChange(val) {
				this.updateMoneyList(val);
			},
			/**切换每页个数 */
			handleSizeChange(val){
				this.searchListParam.pageSize=val;
				this.updateMoneyList();
			},
			/**显示收费、退费管理弹窗 */
			showChargesPopup(type,data,operationType){
				if(!data)return;
				if(!data.signupCourseData)data.signupCourseData=[];
				if(!data.signupGoodsData)data.signupGoodsData=[];
				this.moneyDetailsPopup.operationType=operationType;
				if(operationType==1){
					this.moneyDetailsPopup.title='费用详情';
				}
				else if(operationType==2){
					this.moneyDetailsPopup.title='收费审核';
				}
				let fields=this.getFieldsNameInChargesPopup(type);
				
				let match={
					2:'现金收款',
					3:'微信收款',
					4:'支付宝收款',
					1:'银联收款'
				};
				
				let param={
					//收退费类型
					moneyType:type,
					//操作：1-查看/2-审核
					operationType:operationType,
					title:{
						row1:'学员信息',
						row2:fields.title2
					},
					studentInfo:{
						row1_clo1:{
							name:'学员姓名：',
							value:data.studentName
						},
						row1_clo2:{
							name:'联系人：',
							value:data.parentName
						},
						row1_clo3:{
							name:'联系电话：',
							value:data.studentPhone
						},
						row1_clo4:{
							name:fields.studentInfo.row1_clo4,
							value:data.createTime
						},
						row2_clo1:{
							name:fields.studentInfo.row2_clo1,
							value:data.receiptNo||data.orderNo
						},
						row2_clo2:{
							visible:false,
							name:fields.studentInfo.row2_clo2,
							value:''
						}
					},
					tableObj:{
						type:type,
						statistics:{
							'row1':{
								name:fields.tableObj.row1,
								value:data.realMoney+Number(data.discount)+Number(data.signUpUseEarnestMoney)//应收总计
							},
							'row2':{
								name:fields.tableObj.row2,
								value:data.realMoney//实际收款
							},
							'row3':{
								visible:Number(data.signUpUseEarnestMoney)>0?true:false,
								name:fields.tableObj.row3,
								value:data.signUpUseEarnestMoney//定金抵扣
							}
						},
						table:{
							thead:[],
							tbody:[]
						}
					},
					otherIfo:{
						row1:{
								name:fields.otherIfo.row1,
								value:match[data.payMode]||''
						},
						row2:{
								name:fields.otherIfo.row2,
								value:data.executeUserName
						},
						row3:{
								name:fields.otherIfo.row3,
								value:data.createUserName
						},
						row4:{
								name:fields.otherIfo.row4,
								value:data.remark
						},
						row5:{
								name:'订单号：',
								value:''
						},
						row6:{
								name:'第三方订单号：',
								value:''
						},
						row7:{
								name:'订单状态：',
								value:'已入账'
						},
					}
				};
				if(type=='订金收费'){
					param.otherIfo['row5'].value=-1;//订单号
					param.otherIfo['row6'].value=-1;//第三方订单号

					param.tableObj.table.thead=[{
							propName:'name',
							labelNmae:'名称'
						},
						{
							propName:'money',
							labelNmae:'金额'
						},
						{
							propName:'discount',
							labelNmae:'优惠'
						},
						{
							propName:'receivable',
							labelNmae:'已收款'
						},
					];
					param.tableObj.table.tbody=[];
					param.tableObj.table.tbody.push({
						name:'订金',
						money:'￥'+(data.realMoney||0),
						discount:'￥0',
						receivable:'￥'+(data.realMoney||0)
					});
				}
				else if(type=='报名收费'){
					if(data.orderSignupEntity){
						// param.studentInfo['row1_clo4']['value']=data.orderSignupEntity.orderTime;
						param.otherIfo['row5'].value=data.orderSignupEntity.orderSigupId;//订单号
						param.otherIfo['row6'].value=data.orderSignupEntity.payOrderNo;//第三方订单号
					}
					let statu8='';
					if(data.checkshow)statu8='待审核';
					else if(data.payshow)statu8='待支付';
					else statu8='已入账';
					param.otherIfo.row7.value=statu8;

					param.tableObj.table.thead=[
						{
							propName:'name',
							labelNmae:'名称'
						},
						{
							propName:'totalPrice',
							labelNmae:'总价'
						},
						{
							propName:'unitPrice',
							labelNmae:'单价'
						},
						{
							propName:'unit',
							labelNmae:'单位'
						},
						{
							propName:'count',
							labelNmae:'购买数量'
						},
						{
							propName:'totalMoney',
							labelNmae:'合计金额'
						},
						{
							propName:'discount',
							labelNmae:'优惠'
						},
						{
							propName:'receivable',
							labelNmae:'已收款'
						},
					];
					param.tableObj.table.tbody=[];
					for(let i=0;i<data.signupCourseData.length;i++){
						let row=data.signupCourseData[i];
						let classmode=row.courseMode;
						this._courseMode.forEach((row)=>{
							if(row.value===classmode){
								classmode=row.name;
							}
						});
						let price=(row.courseMoney/row.courseHour).toFixed(2);
						price=isNaN(price)?row.courseMoney:price;
						let unit='课时';
						if(!row.coursePackage){
							unit='';
						}
						else if(row.coursePackage.chargeMode==3){
							unit=this.matchCourseTimeMode(row.coursePackage.courseTimeMode);
						}
						param.tableObj.table.tbody.push({
							classmode:classmode,
							name:(row.courseName?(row.courseName+'\n'):'')+(row.className||''),
							totalPrice:'￥'+(row.courseMoney||0),
							unitPrice:'￥'+(price||0),
							unit:unit,
							count:row.courseHour,
							totalMoney:'￥'+(row.courseMoney||0),
							discount:'￥'+(row.discountMoney||0),
							receivable:'￥'+(row.realMoney||0)
						});
					}
					for(let i=0;i<data.signupGoodsData.length;i++){
						let row=data.signupGoodsData[i];
						param.tableObj.table.tbody.push({
							classmode:'商品',
							name:row.goodsName,
							totalPrice:'￥'+(row.goodsOneMoney*row.goodsNum),
							unitPrice:'￥'+(row.goodsOneMoney||0),
							unit:'个',
							count:row.goodsNum,
							totalMoney:'￥'+(row.totalMoney||0),
							discount:'￥0',
							receivable:'￥'+(row.realMoney||0)
						});
					}
				}
				else if(type=='商品收费'){
					if(data.orderSignupEntity){
						param.otherIfo['row5'].value=data.orderSignupEntity.orderSigupId;//订单号
						param.otherIfo['row6'].value=data.orderSignupEntity.payOrderNo;//第三方订单号
					}

					param.tableObj.table.thead=[
						{
							propName:'name',
							labelNmae:'名称'
						},
						{
							propName:'totalPrice',
							labelNmae:'总价'
						},
						{
							propName:'unitPrice',
							labelNmae:'单价'
						},
						{
							propName:'count',
							labelNmae:'购买数量'
						},
						{
							propName:'totalMoney',
							labelNmae:'合计金额'
						},
						{
							propName:'discount',
							labelNmae:'优惠'
						},
						{
							propName:'receivable',
							labelNmae:'已收款'
						},
					];
					param.tableObj.table.tbody=[];
					
					for(let i=0;i<data.signupGoodsData.length;i++){
						let row=data.signupGoodsData[i];
						param.tableObj.table.tbody.push({
							classmode:'商品',
							name:row.goodsName,
							totalPrice:'￥'+((row.goodsOneMoney*row.goodsNum)||0),
							unitPrice:'￥'+(row.goodsOneMoney||0),
							unit:'个',
							count:row.goodsNum,
							totalMoney:'￥'+(row.totalMoney||0),
							discount:'￥0',
							receivable:'￥'+(row.realMoney||0)
						});
					}
				}
				if(!this.moneyDetailsPopup.data){
					this.moneyDetailsPopup.data=param;
				}
				else{
					this.$refs.chargespopup.updateByData(param)
				}
			},
			/**隐藏收退费详情（审核）弹窗 */
			hideChargesPopup(){
				this.moneyDetailsPopup.visible=false;
			},
			getFieldsNameInChargesPopup(type){
				let fields={
					title2:'',
					studentInfo:{},
					tableObj:{},
					otherIfo:{}
				};
				switch(type){
					case '全部收费':{
						fields.title2='收费详情';
						fields.studentInfo['row1_clo4']='缴费时间：';
						fields.studentInfo['row2_clo1']='合同号：';
						fields.studentInfo['row2_clo2']='';
						fields.tableObj['row1']='应收总计：';
						fields.tableObj['row2']='实际收款：';
						fields.tableObj['row3']='订金抵扣：';
						fields.otherIfo['row1']='缴费方式：';
						fields.otherIfo['row2']='跟单人：';
						fields.otherIfo['row3']='收款人：';
						fields.otherIfo['row4']='备注：';
						break;
					}
					case '报名收费':{
						fields.title2='报名详情';
						fields.studentInfo['row1_clo4']='报名缴费时间：';
						fields.studentInfo['row2_clo1']='合同号：';
						fields.studentInfo['row2_clo2']='';
						fields.tableObj['row1']='应收总计：';
						fields.tableObj['row2']='实际收款：';
						fields.tableObj['row3']='订金抵扣：';
						fields.otherIfo['row1']='缴费方式：';
						fields.otherIfo['row2']='跟单人：';
						fields.otherIfo['row3']='收款人：';
						fields.otherIfo['row4']='备注：';
						break;
					}
					case '商品收费':{
						fields.title2='商品详情';
						fields.studentInfo['row1_clo4']='购买时间：';
						fields.studentInfo['row2_clo1']='收据：';
						fields.studentInfo['row2_clo2']='';
						fields.tableObj['row1']='应收总计：';
						fields.tableObj['row2']='实际收款：';
						fields.tableObj['row3']='订金抵扣：';
						fields.otherIfo['row1']='缴费方式：';
						fields.otherIfo['row2']='跟单人：';
						fields.otherIfo['row3']='收款人：';
						fields.otherIfo['row4']='备注：';
						break;
					}
					case '订金收费':{
						fields.title2='订金详情';
						fields.studentInfo['row1_clo4']='订金缴费时间：';
						fields.studentInfo['row2_clo1']='收据：';
						fields.studentInfo['row2_clo2']='';
						fields.tableObj['row1']='应收总计：';
						fields.tableObj['row2']='实际收款：';
						fields.tableObj['row3']='订金抵扣：';
						fields.otherIfo['row1']='缴费方式：';
						fields.otherIfo['row2']='跟单人：';
						fields.otherIfo['row3']='收款人：';
						fields.otherIfo['row4']='备注：';
						break;
					}
					case '课程退费':{
						fields.title2='退费详情';
						fields.studentInfo['row1_clo4']='退款时间：';
						fields.studentInfo['row2_clo1']='收款人：';
						fields.studentInfo['row2_clo2']='收款人电话：';
						fields.tableObj['row1']='应退总计：';
						fields.tableObj['row2']='实际退款：';
						fields.tableObj['row3']='手动修改退费价格：';
						fields.otherIfo['row1']='退款方式：';
						fields.otherIfo['row2']='跟单人：';
						fields.otherIfo['row3']='退款人：';
						fields.otherIfo['row4']='退费原因：';
						break;
					}
					case '商品退费':{
						fields.title2='退费详情';
						fields.studentInfo['row1_clo4']='退款时间：';
						fields.studentInfo['row2_clo1']='收款人：';
						fields.studentInfo['row2_clo2']='收款人电话：';
						fields.tableObj['row1']='应退总计：';
						fields.tableObj['row2']='实际退款：';
						fields.tableObj['row3']='手动修改退费价格：';
						fields.otherIfo['row1']='退款方式：';
						fields.otherIfo['row2']='跟单人：';
						fields.otherIfo['row3']='退款人：';
						fields.otherIfo['row4']='退费原因：';
						break;
					}
					case '订金退费':{
						fields.title2='退费详情';
						fields.studentInfo['row1_clo4']='退款时间：';
						fields.studentInfo['row2_clo1']='收款人：';
						fields.studentInfo['row2_clo2']='收款人电话：';
						fields.tableObj['row1']='应退总计：';
						fields.tableObj['row2']='实际退款：';
						fields.tableObj['row3']='手动修改退费价格：';
						fields.otherIfo['row1']='退款方式：';
						fields.otherIfo['row2']='跟单人：';
						fields.otherIfo['row3']='退款人：';
						fields.otherIfo['row4']='退费原因：';
						break;
					}
				}
				return fields;
			}
		},
		mounted(){
			this.init();
		},
		computed:{
			
		},
		watch:{

		},
		created:function(){
		}
	}
</script>

<style lang="scss" >
	.moneymanage{
		// position: relative;
		// left: 0.58rem;
		// top: 1.8rem;
		// width: 15.48rem;
		// padding: 0.2rem 0.32rem 0.2rem 0.32rem;
		// height: auto;
		// background: #fff;
		// border: 0.01rem solid #ededed;
		// border-radius: 0.10rem;
		// box-shadow: 0 0.02rem 0.38rem 0 #3885f81f, 0 0 0.06rem 0 #3885f81f;
		.headradioBtn_type{
			width: 8rem;
			position: absolute;
			top: -0.8rem;
			left: .45rem;
			.el-radio-button{
				margin-left: 0.5rem !important;
			}
			.el-radio-button.first{
				margin-left: 0rem !important;
			}
			.el-radio-button__inner{
				width: 1.2rem !important;
				// border-top: 0;
				// border-bottom: 0;
				height: 0.60rem !important;
				line-height: 0.25rem !important;
				font-size: 0.18rem !important;
				border: unset !important;
				border-radius:unset !important;
				background: unset !important;
				color: unset !important;
				line-height: 0.45rem !important;
    			font-size: 0.2rem !important;
			}
			.el-radio-button__orig-radio:checked + .el-radio-button__inner{
				box-shadow:unset !important;
				font-weight: bold !important;
				border-bottom: 0.03rem solid #3885f8 !important;
			}

		}
		.content-moneymanage{
			margin:  0 auto;
			min-width: 15.48rem;
			width: 15.48rem;
			.t-title{
				// position: fixed;
				// left: 2.66rem;
				margin-top: 0.34rem;
				width: 15.48rem;
				font-size: 0.25rem;
				font-weight: bold;
			}
			.headradioBtn_money{
				// position: fixed;
				width: 15.48rem;
				margin-top: 0.14rem;
				// left: 2.66rem;
				// margin-left: 0.20rem;
				.el-radio-button__inner{
					width: 2.799rem;
					height: 0.9rem;
					line-height: 0.25rem;
					font-size: 0.25rem;
					margin-left: 0.37rem;

					background: #fff !important;
					border: 0.01rem solid #ededed !important;
					border-radius: 0.10rem !important;
					box-shadow: 0 0.02rem 0.38rem 0 #3885f81f, 0 0 0.06rem 0 #3885f81f !important;
					display: flex;
					justify-content: flex-start;
					align-content: center;
					align-items: center;
					.btnIco{
						width: 0.56rem;
						height: 0.56rem;
						// position: relative;
						// left: 2%;
						// top: 3%;
					}
					.ccbox{
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						height: 0.56rem;
						margin-left: 0.05rem;
						margin-top: 0.05rem;
						.number{
							// position: relative;
							// display: inline-block;
							// width: 70%;
							// top: -40%;
							text-align: left;
							font-size: 0.30rem;
							font-weight: 800;
							.ico{
								font-size: 0.28rem;
								font-weight: 400;
							}
						}
						.txt{
							// position: relative;
							// left: -70%;
							// width: 70%;
							// top: 0%;
							margin-left: 0.1rem;
							text-align: left;
							display: inline-block;
							font-size: 0.18rem;
						}
					}
					
				}
				.el-radio-button:first-child .el-radio-button__inner{
					margin-left: 0;
				}
				.el-radio-button__orig-radio:checked + .el-radio-button__inner{
					color: #3885f8;
				}
				// .first .el-radio-button__inner{
				// 	border-left: 0;
				// }
				// .last .el-radio-button__inner{
				// 	border-right: 0;
				// }
			}
			.tableBox{
				margin-top: 0.24rem;
				width: 15.48rem;
				padding: 0.2rem 0.32rem 0.2rem 0.32rem;
				height: auto;
				background: #fff;
				border: 0.01rem solid #ededed;
				border-radius: 0.10rem;
				box-shadow: 0 0.02rem 0.38rem 0 #3885f81f, 0 0 0.06rem 0 #3885f81f;
				.headcontrolsbox{
					position: relative;
					width: 100%;
					height: 0.6rem;
					display: flex;
					align-items: center;
					.left{
						width: 50%;
						.payeeselect{
							width: 2rem;
						}
						.paraminput{
							width: 3rem;
						}
						.query{
							
						}
					}
					.right{
						width: 50%;
						text-align: right;
						.timeselect{
							.el-radio-button__orig-radio:checked + .el-radio-button__inner{
									color: #3885f8;
									font-weight: bold;
									background: #FFFFFF;
									border: 0.01rem solid #DCDFE6;
									-webkit-box-shadow: 0.00rem 0 0 0 #FFFFFF;
									box-shadow: 0.00rem 0 0 0 #FFFFFF;
							}
						}
						.el-date-editor{
							right: -2.95rem;
							width: 0.85rem;
							height: 0.39rem;
							pointer-events: none;
							opacity: 0;
						}
					}
				}
				.moneyTable{
					.cell{
						text-align: center;
					}
				}
				.el-pagination{
					text-align: right;
					margin-top: 0.14rem;
				}
			}
			.chargespopup{
				.el-dialog{
					width: 11.84rem !important;
					background-color: white !important;
					border-radius: 0.1rem !important;
					.el-dialog__header{
						.el-dialog__title{
							font-size: 0.22rem !important;
							color: #333333 !important;
							padding: 0rem 0.1rem 0rem 0.1rem;
							font-weight: bold;
						}
					}
					.el-dialog__body{
						font-size: 0.16rem !important;
						color: #666666 !important;
						padding: 0.2rem 0.3rem  !important;
					}
				}
			}
			.checkpopup{
				top: 0.81rem !important;
        		left: 2.1rem !important;
				.el-dialog {
					width: 4.5rem !important;
					.el-dialog__header{
						text-align: center;
						.el-dialog__title{
							font-size: 0.2rem;
							font-weight: bold;
						}
					}
					.el-dialog__body{
						padding: 0.1rem 0.5rem !important;
						font-size: 0.16rem !important;
						.el-row{
							margin-top: 0.05rem;
						}
					}
					.el-dialog__footer{
						text-align: center !important;
					}
				}
			}
		}
		.paySuccess{
			.el-dialog {
				width: 13rem !important;
				// min-height: 100%;
				// margin-top: 38vh !important;
				.el-dialog__header {
					display: none;
				}
				.el-dialog__body{
					font-size: 0.16rem !important;
				}
				.el-dialog__title {
					font-size: 0.25rem;
					font-weight: bold;
					color: #333333;
				}
				.el-dialog__headerbtn {
					font-size: 0.25rem !important;
				}
			}
		}

		//鼠标悬浮
		.hoverpointer:hover{
			cursor: pointer;
		}
		// 滚动条
		.scrollbarstyle::-webkit-scrollbar {
			width: 0.05rem;
		}
		.scrollbarstyle::-webkit-scrollbar-thumb {
			border-radius: 0.5rem;
			background: #BBBBBB;
		}
		.scrollbarstyle::-webkit-scrollbar-track {
			background: #F2F6FC;
		}
		.el-table__body-wrapper::-webkit-scrollbar {
			width: 0.05rem;
		}
		.el-table__body-wrapper::-webkit-scrollbar-thumb {
			border-radius: 0.5rem;
			background: #BBBBBB;
		}
		.el-table__body-wrapper::-webkit-scrollbar-track {
			background: #F2F6FC;
		}
	}
	// 搜索框样式
	.comSearchInput .el-input__inner {
		background-color: #f7f8fa;
		border-radius: 0.08rem;
		font-size: 0.16rem;
		color: #666666;
		height: 0.36rem !important;
		line-height: 0.36rem !important;
	}
</style>